<?php
$this->headTitle('Danh sách game', 'append');
?>
<div class="grid">
    <div class="breadcrumbs">
        <a class="item-1" href="/index">Trang chủ CI</a> › 
        <span class="blue">Danh sách game</span>
        <div class="clear-both"></div>
    </div>
    <div class="menu-listgame">
        <div class="parent-menu">
            <?php 
                foreach($this->allCateList as $row){ 
                    if($row['total'] <= 0 || $row['parentId'] != 0){
                        continue;
                    }
            ?>
                    <a href="javascript: void(0)" index="<?php echo $row['catId'];?>" <?php if(isset($this->cookie_parent_menu) && $this->cookie_parent_menu == $row['catId']) echo 'class="active"';?>><?php echo $row['catName'].' ('.$row['total'].')';?></a>
            <?php 
                } 
            ?>
        </div>
        <div class="clear-both"></div>
    </div>
    <div class="clear-both"></div>
    <div class="content-listgame">
        <div class="child-menu">
            <?php 
                foreach($this->allCateList as $row){ 
                    if($row['parentId'] == 0 || $row['total'] <= 0){
                        continue;
                    }
            ?>
                <div class="<?php if(isset($this->cookie_parent_menu) && $this->cookie_parent_menu != $row['parentId']){echo 'hidden parentId-'.$row['parentId'];}else {echo 'parentId-'.$row['parentId'];}?>">
                <a href="javascript: void(0)" parentId="<?php echo $row['parentId'];?>" index="<?php echo $row['catId'];?>" class="<?php echo $row['catId'].' '; if(isset($this->cookie_child_menu) && $this->cookie_child_menu == $row['catId']) echo 'active ';?>">
                    <?php 
                        for($i =0; $i < strlen($row['catName']); $i++)
                        {
                            echo $row['catName'][$i]."<br />";
                        }
                    ?>
                </a>
                </div>
            <?php } ?>
        </div>
        <ul class="gameList">
            <?php
                $stt = 1;
                if(isset($this->gameList))
                foreach($this->gameList as $game){
                    if(isset($game['homepage'][0])){
                        $homepage = $game['homepage'].'/game/'.$game['gameId'];
                        //echo $homepage."<br />";
                    }else{
                        $homepage = $this->modelRole->getDataByUserIdGameId($this->auth['userId'], $game['gameId']);
                        $homepage = (isset($homepage['homepage']) && $homepage['homepage']) 
                                    ? $homepage['homepage'].'/game/'.$game['gameId'] 
                                    : '/transaction/index/game/'.$game['gameId'];
                    }
            ?>
                <li class="item-<?php echo $stt.' catId-'.$game['catId'].' catId-'.$game['parentId']; if((isset($this->cookie_parent_menu) && $this->cookie_parent_menu != $game['parentId']) || (isset($this->cookie_child_menu) && $this->cookie_child_menu != $game['catId'])) echo ' hidden';else echo ' display';?>">
                    <a class="img loading" href="<?php echo $homepage;?>" title="<?php echo $game['gameName'];?>"><img src="<?php echo $game['gameImg'];?>" title="<?php echo $game['gameName'];?>" alt="<?php echo $game['gameName'];?>"/></a>
                    <a class="tit loading" href="<?php echo $homepage;?>" title="<?php echo $game['gameName'];?>"><?php echo $game['gameName'].'<br />('.$game['gameId'].')';?></a>
                </li>
            <?php
                    if($stt == 4)
                        $stt = 1;
                    else
                        ++$stt;
                } 
            ?>
        </ul>
        <div class="clear-both"></div>
    </div>
    <div class="clear-both"></div>
</div>
<script type="text/javascript">

    $(document).ready(function(){
        $('.menu-listgame a').click(function(){
            $(this).parent().find('a').removeClass('active');
            $(this).addClass('active');
            var parent_menu = $(this).attr('index');
            $('.gameList li.display').addClass('hidden');
            $('.gameList li.display').removeClass('display');
            $('.content-listgame .child-menu div a').removeClass('active');
            $('.content-listgame .child-menu div').addClass('hidden');
            $('.content-listgame .child-menu div.parentId-'+parent_menu).addClass('active');
            $('.content-listgame .child-menu div.parentId-'+parent_menu).removeClass('hidden');
            var child_menu = $('.content-listgame .child-menu div.parentId-'+parent_menu).find('a').attr('index');
            $('.content-listgame .child-menu div.parentId-'+parent_menu+' a.'+child_menu).addClass('active');
            $('ul.gameList li.catId-'+child_menu).removeClass('hidden');
            $('ul.gameList li.catId-'+child_menu).addClass('display');
            t = new Date();
            t.setMinutes(t.getMinutes() + 60);
            $.cookie('<?php echo 'parent-menu';?>', parent_menu, {expires : t, path: '/'});
            $.cookie('<?php echo 'child-menu';?>', child_menu, {expires : t, path: '/'});
        });
        $('.content-listgame .child-menu div a').click(function(){
            $(this).parent().parent().find('a').removeClass('active');
            $(this).addClass('active');
            var child_menu = $(this).attr('index');
            $('.gameList li.display').addClass('hidden');
            $('.gameList li.display').removeClass('display');
            $('ul.gameList li.catId-'+child_menu).removeClass('hidden');
            $('ul.gameList li.catId-'+child_menu).addClass('display');
            t = new Date();
            t.setMinutes(t.getMinutes() + 60);
            $.cookie('<?php echo 'child-menu';?>', child_menu, {expires : t, path: '/'});
            
        });
      ;      
    })
</script>